package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.controller.member.service.BindingFamilyMemberService;
import com.zzyl.nursing.controller.member.service.MemberHealthyDataservice;
import com.zzyl.nursing.domain.AlertData;
import com.zzyl.nursing.dto.*;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 老人家属Controller
 * 
 * @author ruoyi
 * @date 2025-04-26
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;
    @Autowired
    private BindingFamilyMemberService bindingfamilyMemberService;
    @Autowired
    private MemberHealthyDataservice memberHealtyDataservice;
    /**
     * 登录小程序端
     */
    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto userLoginRequestDto) {
        LoginVo loginVo = familyMemberService.login(userLoginRequestDto);
        return success(loginVo);
    }
    /**
     * 查询绑定老人家属信息
     */
    @PostMapping("/add")
    @ApiOperation("绑定老人家属信息")
    public AjaxResult add(@RequestBody BindingElderInfoDto bindingElderInfoDto) {
        bindingfamilyMemberService.bindingFamilyMember(bindingElderInfoDto);
        return success();
    }
    /**
     * 查询健康数据
     */
    @GetMapping("/queryServiceProperties/{iotId}")
    @ApiOperation("查询健康数据")
    public R<List<HealthyDataVo>> queryServiceProperties(@PathVariable String iotId) {
        List<HealthyDataVo> healthyDataVos = memberHealtyDataservice.queryServiceProperties(iotId);
        return R.ok(healthyDataVos);
    }
    /**
     *  查询家人列表
     */
    @GetMapping("/my")
    @ApiOperation("查询家人列表")
    public R<List<BindingElderInfoVo>> my() {
        List<BindingElderInfoVo> bindingElderInfoVos = memberHealtyDataservice.selectBindingElderInfoVoList();
        return R.ok(bindingElderInfoVos);
    }
    /**
     *  查看已绑定家人列表（分页查询）
     */
    @GetMapping("/list-by-page")
    @ApiOperation("查看已绑定家人列表（分页查询）")
    public R<List<ElderMessageVo>> listByPage() {
        List<ElderMessageVo> bindingElderInfoVos = memberHealtyDataservice.selectElderMessageVoList();
        return R.ok(bindingElderInfoVos);
    }

    /**
     *  解绑老人
     */
    @PostMapping("/deleteById")
    @ApiOperation("解绑老人")
    public R<String> deleteById(@RequestParam Long id) {
        bindingfamilyMemberService.deleteElderById(id);
        return R.ok("解绑成功");

    }
    //查询健康数据
    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("查询健康数据")
    public R<HealthyReturnVo> QueryDevicePropertyStatus(@RequestBody DeviceMessageDto deviceMessageDto){
        String deviceName = deviceMessageDto.getDeviceName();
        String productKey = deviceMessageDto.getProductKey();
        HealthyMessageVo healthyMessageVo = memberHealtyDataservice.queryDeviceServiceProperties(deviceName, productKey);
        HealthyReturnVo healthyReturnVo = new HealthyReturnVo();
        healthyReturnVo.setList(healthyMessageVo);
        return R.ok(healthyReturnVo);
    }
    //按天统计查询指标数据
    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public R<List<DeviceDataByDay>> queryDeviceDataListByDay(
            @RequestParam String iotId,
            @RequestParam String functionId,
            @RequestParam Long startTime,
            @RequestParam Long endTime) {
        {
            List<DeviceDataByDay> result = memberHealtyDataservice.queryDeviceDataListByDay(iotId, functionId, startTime, endTime);
            return R.ok(result);

        }
    }
    //按周统计查询指标数据
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周统计查询指标数据")
    public R<List<DeviceDataByDay>> queryDeviceDataListByWeek(
            @RequestParam String iotId,
            @RequestParam String functionId,
            @RequestParam Long startTime,
            @RequestParam Long endTime) {
        {
            List<DeviceDataByDay> result = memberHealtyDataservice.queryDeviceDataListByWeek(iotId, functionId, startTime, endTime);
            return R.ok(result);

        }
    }
    //分页查询预警数据
    @GetMapping("/pageQueryAlertData")
    @ApiOperation("分页查询预警数据")
    public R<List<AlertData>> pageQueryAlertData(AlertDataDto alertDataDto) {
        List<AlertData> result = memberHealtyDataservice.pageQueryAlertData(alertDataDto);
        return R.ok(result);
    }
}
